import { isValid, Slider } from "cc";
import { Observable } from "rxjs";

export function BindSlider(slider: Slider): Observable<{ state: string, target: Slider }> {
    return new Observable((observer) => {
        let scrolling = () => {
            observer.next({ state: 'slide', target: slider });
        }
        slider.node.on('slide', scrolling, this);
        return () => {
            if (isValid(slider.node)) slider.node.off('slide', scrolling);
        }
    });
};